package com.lx.oms.controller.manager.impl;

import java.math.BigInteger;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lx.oms.common.entity.Query;
import com.lx.oms.common.utils.CommonUtils;
import com.lx.oms.common.utils.Utils;
import com.lx.oms.controller.dao.SupplyCategoryMapper;
import com.lx.oms.controller.entity.SupplyCategoryEntity;
import com.lx.oms.controller.manager.SupplyCategoryManager;

/**
 * 黄页分类
 *
 * @author houzhong
 * @date 2018年11月22日 上午10:10:19
 */
@Component("supplyCategoryManager")
public class SupplyCategoryManagerImpl implements SupplyCategoryManager {

	@Autowired
	private SupplyCategoryMapper supplyCategoryMapper;
	
	@Override
	public List<SupplyCategoryEntity> listCategoryByParentId(Query query) {
		return supplyCategoryMapper.listCategoryByParentId(query);
	}

	@Override
	public int saveSupplyCategory(SupplyCategoryEntity supplyCategory) {
		if (supplyCategory.getId() == null) {
			supplyCategory.setId(Utils.id().toString());
		}
		return supplyCategoryMapper.save(supplyCategory);
	}

	@Override
	public SupplyCategoryEntity getSupplyCategoryById(BigInteger id) {
		SupplyCategoryEntity tSupplyCategory = supplyCategoryMapper.getObjectById(id);
		return tSupplyCategory;
	}

	@Override
	public int updateSupplyCategory(SupplyCategoryEntity supplyCategory) {
		return supplyCategoryMapper.update(supplyCategory);
	}

	@Override
	public int batchRemove(String[] id) {
		int count = supplyCategoryMapper.batchRemove(id);
		return count;
	}

	@Override
	public boolean hasChildren(String[] id) {
		for(String typeId : id) {
			int count = supplyCategoryMapper.countCategoryChildren(typeId);
			if(CommonUtils.isIntThanZero(count)) {
				return true;
			}
		}
		return false;
	}

	@Override
	public SupplyCategoryEntity getCategoryByName(Query query) {
		SupplyCategoryEntity supplyCategoryEntity = supplyCategoryMapper.getCategoryByName(query);
		return supplyCategoryEntity;
	}

	@Override
	public List<SupplyCategoryEntity> getCategoryByParentId(Query query) {
		List<SupplyCategoryEntity> supplyCategoryEntity = supplyCategoryMapper.getCategoryByParentId(query);
		return supplyCategoryEntity;
	}

	
	
}
